package com.selebash.runtime;

import com.selebash.config.Config;
import com.selebash.Localization;
import com.selebash.SelebashParser;
import com.selebash.ast.AbstractAst;
import com.selebash.exception.SelebashException;
import com.selebash.scripts.Script;

/**
 * @author sad
 */
public class SelebashRunner {

    public void run(Script testCase, Config config) {
        ExecutionContext executionContext = new ExecutionContext();
        AbstractAst node = testCase.getAstNodes().get(SelebashParser.DefaultFunctionName);
        if (node == null) {
            throw new SelebashException(config.getLocalization().getString(Localization.TEST_CASE_SHOULD_CONTAIN_STEPS_RULE));
        }

        node.process(executionContext);
    }

    public void run(ExecutionContext executionContext) {
        
        Script script = executionContext.getMainScript();
        AbstractAst node = script.getFunctionNode(SelebashParser.DefaultFunctionName);
        if (node == null) {
            throw new SelebashException(executionContext.getConfig().getLocalization().getString(Localization.TEST_CASE_SHOULD_CONTAIN_STEPS_RULE));
        }

        node.process(executionContext);
    }
}
